<template>
  <div>
    <el-drawer
        title="编辑"
        :visible.sync="dialogVisible"
        :direction="direction"
        @close="handleClose"
        >
        <el-form
            :model="data"
            label-width="100px"
        >
            <el-form-item label="商品名称:">
                <el-input v-model="data.name"></el-input>
            </el-form-item>
            <!--  -->
            <el-form-item label="订单数量:">
                <el-input v-model="data.num"></el-input>
            </el-form-item>
            <!--  -->
            <el-form-item label="财务状态:">
                <el-switch v-model="data.state"></el-switch>
            </el-form-item> 
            <!--  -->
            <el-button type="primary" @click="handleClick">确 定</el-button>
            <div class="danger">
                <p style="color: #F56C6C; font-size: 13px;">请确保您拥有权限,不免造成不必要的后果</p>
            </div>
        </el-form>
    </el-drawer>
    
    <el-dialog
        title="权限验证"
        :visible.sync="visible"
        @close="handleClosePro"
        width="30%"
        :before-close="handleClosePro">
        <el-form 
            status-icon label-width="100px" 
            :model="ruleForm"
            ref="formDom"
            >
            <el-form-item label="工号" prop="username">
                <el-input type="text" v-model="ruleForm.username" autocomplete="off"></el-input>
            </el-form-item>
            <el-form-item label="密码" prop="password">
                <el-input type="password" v-model="ruleForm.password" autocomplete="off"></el-input>
            </el-form-item>
        </el-form>
        <span slot="footer">
            <el-button @click="handleClosePro">取 消</el-button>
            <el-button type="primary" @click="handleClickTrue">确 定</el-button>
        </span>
    </el-dialog>
  </div>
</template>

<script>
  export default {
    name: 'DRAWER',
    data() {
        // var validatePass = (rule, value, callback) => {
        //     if (value === '') {
        //         callback(new Error('请输入工号'));
        //     } else {
        //         if (this.ruleForm.checkPass !== '') {
        //             this.$refs.ruleForm.validateField('checkPass');
        //         }
        //         callback();
        //     }
        // };
        // var validatePass2 = (rule, value, callback) => {
        //     if (value === '') {
        //         callback(new Error('请输入密码'));
        //     } else {
        //         if (this.ruleForm.checkPass !== '') {
        //             this.$refs.ruleForm.validateField('checkPass');
        //         }
        //         callback();
        //     }
        // };
        return {
            dialogVisible:this.value,
            visible:false,
            direction: 'rtl',
            data:{
                name: '',
                num: 1,
                state: true
            },
            ruleForm : {
                username:'',
                password:''
            },
            // rules: {
            //     pass: [
            //         { validator: validatePass, trigger: 'blur' }
            //     ],
            //     checkPass: [
            //         { validator: validatePass2, trigger: 'blur' }
            //     ],
            // }
        };
    },
    props:{
        value:{
            type:Boolean,
        },
        commodityData: {
            type:Object
        }
    },
    methods: {
        handleClosePro() {
            this.visible = false;
            this.$refs.formDom.resetFields();
        },
        handleClose() {
            // console.log('close');
            this.$emit("input", false)
        },
        handleClick() {
            this.visible = true
        },
        handleClickTrue() {
            this.$message.error('对不起您的权限不足,请联系相关部门');
        }
    },
    watch: {
        value() {
            this.dialogVisible = this.value;
        },
        commodityData() {
            this.data = {...this.commodityData}
        }
    },
  };
</script>

<style scoped lang = 'less'>
.el-form {
    // position: relative;
    .el-form-item {
            margin: 50px 0 50px 0;
        }
    
        div {
            p {
                margin: 20px 0 0 120px;
            }
        }
    
        .el-button {
            width: 200px;
            margin-left: 140px;
        }
}
</style>